import { reactive } from 'vue';
import { defineStore } from 'pinia';
import { api as Request } from '@/utils/api';

/* 选项试的写法 */
// export const useUserStore = defineStore('user', {

// state: () => {
//   return {
//     userInfo: {
//       agency_name: '',
//       role_name: '',
//       user_name: '',
//       nick_name: '',
//       mobile: '',
//       avatar: '',
//     }
//   };
// },
// getters: {},
// actions: {
//   /* 获取用户信息 */
//   getUserInfoInfo (data) {
//     return Request.getUserInfoInfo(data);
//   },
//   /* 修改用户信息 */
//   setUserInfo (data) {
//     this.userInfo.agency_name = data.agency_name;
//     this.userInfo.role_name = data.role_name;
//     this.userInfo.user_name = data.user_name;
//     this.userInfo.nick_name = data.nick_name;
//     this.userInfo.mobile = data.mobile;
//     this.userInfo.avatar = data.avatar;
//   }
// }
// });

/* 组合式的写法 */
export const useUserStore = defineStore('user', () => {
  const userInfo = reactive({
    agency_name: '',
    role_name: '',
    user_name: '',
    nick_name: '',
    mobile: '',
    avatar: ''
  })
  /* 获取用户信息 */
  function getUserInfoInfo (data) {
    return Request.getUserInfoInfo(data);
  }
  /* 修改用户信息 */
  function setUserInfo (data) {
    userInfo.agency_name = data.agency_name;
    userInfo.role_name = data.role_name;
    userInfo.user_name = data.user_name;
    userInfo.nick_name = data.nick_name;
    userInfo.mobile = data.mobile;
    userInfo.avatar = data.avatar;
  }
  return { userInfo, getUserInfoInfo, setUserInfo }
})
